import allure

from src.api.base_api import BaseApi
from src.utils.data_model import data_model_list
from src.utils.get_today_time import get_today_time_start, get_today_time_end


class Analysis(BaseApi):
    def __init__(self, base_url):
        super().__init__(base_url)
    @allure.step('获取数据列表')
    def list(self,platform='dy',**kwargs):
        '''
        数据概览模块，选择完筛选条件后，展示数据列表
        url=https://ck-medium-api-test.cds8.cn/v1/analysis/new/data_trend
        get
        默认参数为获取当天的数据
        '''
        params={
            'platform':platform
        }

        for k, v in kwargs.items():
            params[k] = v

        # params_model = data_model_list.model_validate(params)
        #
        # params = params_model.model_dump()

        res_json = self.send(method='get',path='analysis/new/data_trend',params=params)

        return res_json

    @allure.step('获取出单商品数量')
    def list_sport_goods(self,platform='dy',start_time=get_today_time_start(),end_time=get_today_time_end()):
        '''
        用于在数据概览-动销数据-获取出单商品数
        url=https://ck-medium-api-test.cds8.cn/v1/analysis/new/sport_goods
        get

        '''
        params={
            'page':1,
            'size':10,
            'platform':platform,
            'start_time':start_time,
            'end_time':end_time
        }
        res_json = self.send(method='get',path='analysis/new/sport_goods',params=params)

        return res_json


